package com.etrans.web.gps.business.base.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.etrans.web.gps.base.service.BaseService;
import com.etrans.web.gps.business.base.domain.TerminalKind;


/**
 * 终端类型service层
 * @author liurong
 *
 */
@Service
public class TerminalKindService extends BaseService {
	
	/**
	 * 查询所有的终端类型信息树	
	 * @return 
	 */
	public List<TerminalKind> loadAllTerminalKindTrees(){
		return selectList("terminalKindQuery.loadAllTerminalKindTrees", 1);
	}
	
	
	/**
	 * 添加终端类型信息
	 * @param terminalkind
	 */
	@Transactional(readOnly = false, rollbackFor = { DataAccessException.class,
			Exception.class })
	public void saveTerminalKind(TerminalKind terminalkind) {

		this.insert( "terminalKindMapper.saveTerminalKind", terminalkind);
		/*String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
		buffer.append("添加新的终端类型->终端类型名称 : " + terminalkind.getName() +", 终端类型编号" + terminalkind.getKind()+"!");
		this.insert("insertTerminalKindLog", this.insertTerminalKindLog(request,methodName));
		buffer.delete(0, buffer.length());*/
	}
	
	/**
	 * 修改终端类型信息
	 * @param terminalkind
	 */
	@Transactional(readOnly = false, rollbackFor = { DataAccessException.class,
			Exception.class })
	public void updateTerminalKind(TerminalKind terminalkind) {
		this.update("terminalKindMapper.updateTerminalKind", terminalkind);
		/*TerminalKind oldTerminalKind = (TerminalKind) oldTerminalKindMap.get("oldTerminalKind");
		String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
		createTerminalKindDescribeString(terminalkind,oldTerminalKind);
		this.insert("insertTerminalKindLog", this.insertTerminalKindLog(request,methodName));
		buffer.delete(0, buffer.length());*/
		
	}
	
	
	/**
	 * 删除终端类型信息
	 * @param id
	 */
	@Transactional(readOnly = false, rollbackFor = { DataAccessException.class,
			Exception.class })
	public void deleteTerminalKindByID( Integer id) {
		//TerminalKind terminalKind = queryTerminalKindById(id);
		this.delete("terminalKindMapper.deleteTerminalKindByID", id);
		/*String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
		buffer.append("删除终端类型->终端类型名称: "+terminalKind.getName() + ",");
		this.insert("insertTerminalKindLog", this.insertTerminalKindLog(request,methodName));
		buffer.delete(0, buffer.length());*/
	}
	
	/**
	 * 根据ID获取终端类型信息
	 * @param id
	 * @return
	 */
	public TerminalKind queryTerminalKindById(Integer id) {
		TerminalKind terminalkind = (TerminalKind) this.selectOne("terminalKindQuery.queryTerminalKindById", id);
		//oldTerminalKindMap.put("oldTerminalKind", terminalkind);
		return terminalkind;
	}
	
	/**
	 * 查询所有的终端类型信息
	 * @param param
	 * @return
	 */
	public List<TerminalKind> queryAllTerminalKinds( Map<String, Object> param) {
		return selectList("terminalKindQuery.queryAllTerminalKinds",param);
	}

	/**
	 * 查询终端总数
	 * @param param
	 * @return
	 */
	public int terminalkindCount( Map<String, Object> param) {
		return (int) this.selectOne("terminalKindQuery.terminalkindCount", param);
	}
	
	
	/**
	 * 查询所有终端
	 * @return
	 */
	public List<TerminalKind> queryTerminalKinds() {
		return selectList("terminalKindQuery.queryTerminalKinds", 1);
	}


	public Integer queryCountByName(HashMap<String, Object> parms) {
		
		return(Integer) this.selectOne("terminalKindQuery.queryCountByName", parms);
	}
	
	public Integer queryCountByKind(HashMap<String, Object> parms) {
		
		return(Integer) this.selectOne("terminalKindQuery.queryCountByKind", parms);
	}
}
